package com.boilerCloud.service.user;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.boilerCloud.dao.sys.IHzlqswUserDao;
import com.boilerCloud.dao.user.AppUserDao;
import com.boilerCloud.dto.HzlqswPage;
import com.boilerCloud.dto.sys.User;
import com.boilerCloud.dto.user.AppUser;
import com.boilerCloud.util.MD5;
@Service
public class AppUserService  implements IAppUserService{

	@Resource
	private AppUserDao dao;
	
	@Resource
	private IHzlqswUserDao userdao;
	@Override
	public void qryList(AppUser model, HzlqswPage<AppUser> page)throws Exception {
		dao.qryList(model,page);
		
	}

	@Override
	public void edit(AppUser model)throws Exception {
		dao.edit(model);
		if(model.getUserType() != 2  ){//非供应商插入 user_base
			User user = new User();
			user.setName(model.getName());
			user.setCellPhone(model.getCellPhone());
			user.setDealerId(model.getId());
			userdao.editUserByDealerId(user);
		}
		
	}

	@Override
	public void save(AppUser model) throws Exception{
		model.setPassword(MD5.getMD5(model.getPassword()));
		dao.save(model);
		int id = model.getId();
		if(model.getUserType() != 2  ){//非供应商插入 user_base
			User user = new User();
			user.setAccount(model.getAccount());
			user.setName(model.getName());
			user.setCellPhone(model.getCellPhone());
			user.setPwd(model.getPassword());
			user.setDealerId(id);
			user.setUserType(model.getUserType());
			int roleId = 3;
			if(model.getUserType() == 1){
				roleId = 2 ;
			}
			user.setRoleId(roleId);
			userdao.addUser(user);
		}
		
	}

	@Override
	public AppUser getAppUserInfo(int id) throws Exception{
		// TODO Auto-generated method stub
		return dao.getAppUserInfo(id);
	}
	@Override
	public AppUser getAppUserInfoByAccount(String  account) throws Exception{
		// TODO Auto-generated method stub
		return dao.getAppUserInfoByAccount(account);
	}

	@Override
	public List<AppUser> getAppUserList(AppUser object)throws Exception {
		// TODO Auto-generated method stub
		return dao.getAppUserList(object);
	}

	@Override
	public void del(int id) throws Exception{
		dao.del(id);
		
	}

	



}
